package com.duke.shaking.profile;

import java.util.ArrayList;
import java.util.List;

import com.duke.shaking.R;
import com.duke.shaking.pojo.UserImage;
import com.duke.shaking.widget.gallery.GalleryAdapter;
//import com.duke.shaking.widget.GalleryView;
//import com.duke.shaking.widget.GalleryViewPagerAdapter;
import com.duke.shaking.widget.gallery.GalleryExt;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
//import android.support.v4.view.ViewPager;
//import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Window;
import android.view.WindowManager;

public class ViewPhotosPagerActivity extends Activity {
	public static final String EXTRA_IMAGES = "images";
	public static final String EXTRA_POSITION = "position";
	//private ViewPager viewPager;
	private GalleryExt gallery;
	private GalleryAdapter adapter;
	
	public ViewPhotosPagerActivity() {
		super();
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		// full screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);  
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
		Intent i = getIntent();
		List<UserImage> imageList = (List<UserImage>)i.getSerializableExtra(EXTRA_IMAGES);
		int position = i.getIntExtra(EXTRA_POSITION, 0);
		
		setContentView(R.layout.activity_gallery4);
		
		/*this.viewPager = (ViewPager)this.findViewById(R.id.gallery);
		
		GalleryViewPagerAdapter adapter = new GalleryViewPagerAdapter(this, imageList);
		this.viewPager.setAdapter(adapter);
		this.viewPager.setOffscreenPageLimit(imageList.size());
		this.viewPager.setClipChildren(false);
		this.viewPager.setOnPageChangeListener(new ViewPagerChangeListener());
		
		// show the image user clicks on thumbnail
		this.viewPager.setCurrentItem(position, false);
		*/
		gallery = (GalleryExt)findViewById(R.id.gallery);
		List<String> imagesUrl = new ArrayList<String>();
		List<String> thumbnailsUrl = new ArrayList<String>();
		if (imageList != null) {
			for (UserImage ui : imageList) {
				if (ui != null) {
					imagesUrl.add(ui.getUrl());
					thumbnailsUrl.add(ui.getUrl_1());
				}
			}
		}
		adapter = new GalleryAdapter(this, imagesUrl, thumbnailsUrl);
		gallery.setAdapter(adapter);
		if (position >= 0 && position < imagesUrl.size()) {
			gallery.setSelection(position);
		}
	}
	
	/*
	private class ViewPagerChangeListener implements OnPageChangeListener {

		public void onPageScrollStateChanged(int arg0) {
			// TODO Auto-generated method stub
			
		}

		public void onPageScrolled(int arg0, float arg1, int arg2) {
			// TODO Auto-generated method stub
			
		}

		public void onPageSelected(int arg0) {
			// TODO Auto-generated method stub
			
		}
		
	}
*/
	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		this.finish();
	}
	
}
